/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package traffic;

import com.google.code.eventsonfire.EventHandler;
import comunicacao.GestorZooKeeper;
import entities.Server;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author Leonardo Lino Nº45340
 * @author Diogo Pires Nº40351
 */
public class ControladorTrafego {
    
    public static Server selectedServer;
    
    private ArrayList<Server> servers;
    
    
    public static final int LOAD_TYPE_CONSTANT= 0;
    public static final int LOAD_TYPE_PROGRESSIVE= 1;
    private int loadType;

    private Configuracao config;
    GeradorPanel geradorPainel;
    
    private GestorZooKeeper gestorZK;

    public ControladorTrafego() {
        loadZooKeeperServers();
    }
    
    
    
    
    private void loadZooKeeperServers(){
        gestorZK = new GestorZooKeeper();
        servers = gestorZK.getAllServers();
    }
    
    
    public void start(){
        launchGestorThreads();
    }
    
    
    private void launchGestorThreads(){
        int pedidos = geradorPainel.pedidosSlider.getValue();
        int segundos = Integer.parseInt(geradorPainel.segundosField.getText());
        int numThreads = Integer.parseInt(config.numThreadsField.getText());
       
        
        selectedServer = servers.get(geradorPainel.comboServer.getSelectedIndex());
        
        
        
        Runnable task = new GestorThreads(pedidos, segundos, numThreads,
                config.checkListaTeatros.isSelected(), config.checkTeatro.isSelected());
        
       Thread worker = new Thread(task);
       worker.setName("Gestor Threads");
       worker.start();  
        
    }
    
    

    public void setConfig(Configuracao config) {
        this.config = config;
        
    }

    public void setGeradorPainel(GeradorPanel geradorPainel) {
        this.geradorPainel = geradorPainel;
        System.out.println("set gerador");
        
       
       int load = geradorPainel.comboType.getSelectedIndex();
       loadType =load;
    }

    public ArrayList<Server> getServers() {
        return servers;
    }
    
    
    
}
